﻿/*
Copyright (c) 2008 William Duff

Permission is hereby granted, free of charge, to any person obtaining a copy 
of this software and associated documentation files (the "Software"), to deal 
in the Software without restriction, including without limitation the rights 
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all 
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 
SOFTWARE.
*/

using System;
using System.Collections.Generic;
using System.Text;

namespace LiveUpload.YouTube
{
    /// <summary>
    /// Data related to an item in the session data.
    /// </summary>
    class Item
    {
        /// <summary>
        /// Constructs a new Item object to represent an item to be uploaded.
        /// </summary>
        public Item(string id, string fullFilePath, string fileName, string fileExtension,
            string perceivedType, string title, int width, int height, int lengthMS, int fileSize,
            List<string> keywordSet)
        {
            this.id = id;
            this.fullFilePath = fullFilePath;
            this.originalFileName = fileName;
            this.originalFileExtension = fileExtension;
            this.perceivedType = perceivedType;
            this.title = title;
            this.originalWidth = width;
            this.originalHeight = height;
            this.lengthMS = lengthMS;
            this.fileSize = fileSize;
            this.keywordSet = keywordSet;
        }

        /// <summary>
        /// Constructs a new Item object to represent an item to be uploaded.
        /// </summary>
        public Item(string id, string fullFilePath, string fileName, string fileExtension,
            string perceivedType, string title, int width, int height, int lengthMS, int fileSize,
            List<string> keywordSet, string description, string category, string url)
        {
            this.id = id;
            this.fullFilePath = fullFilePath;
            this.originalFileName = fileName;
            this.originalFileExtension = fileExtension;
            this.perceivedType = perceivedType;
            this.title = title;
            this.originalWidth = width;
            this.originalHeight = height;
            this.lengthMS = lengthMS;
            this.fileSize = fileSize;
            this.keywordSet = keywordSet;
            this.description = description;
            this.category = category;
            this.url = url;
        }

        // Private variables.
        private string id;
        private string fullFilePath;
        private string originalFileName;
        private string originalFileExtension;
        private string perceivedType;
        private string title;
        private int originalWidth;
        private int originalHeight;
        private int lengthMS;
        private int fileSize;
        private List<string> keywordSet = new List<string>();
        private string description;
        private string category;
        private string url;

        /// <summary>
        /// Unique identifier for the item.
        /// </summary>
        public string Id
        {
            get { return this.id; }
        }

        /// <summary>
        /// The absolute file path of the item.
        /// </summary>
        public string FullFilePath
        {
            get { return this.fullFilePath; }
        }

        /// <summary>
        /// The file name of the item.
        /// </summary>
        public string OriginalFileName
        {
            get { return this.originalFileName; }
        }

        /// <summary>
        /// The file extension of the item.
        /// </summary>
        public string OriginalFileExtension
        {
            get { return this.originalFileExtension; }
        }

        /// <summary>
        /// The type of the item ('video' or 'image').
        /// </summary>
        public string PerceivedType
        {
            get { return this.perceivedType; }
        }

        /// <summary>
        /// Title of the item.
        /// </summary>
        public string Title
        {
            get { return this.title; }
            set { this.title = value; }
        }

        /// <summary>
        /// The original width of the item in pixels.
        /// </summary>
        public int OriginalWidth
        {
            get { return this.originalWidth; }
        }

        /// <summary>
        /// The original height of the item in pixels.
        /// </summary>
        public int OriginalHeight
        {
            get { return this.originalHeight; }
        }

        /// <summary>
        /// The LengthMS element.
        /// </summary>
        public int LengthMS
        {
            get { return this.lengthMS; }
        }

        /// <summary>
        /// The file size of the item in kilobytes.
        /// </summary>
        public int FileSize
        {
            get { return this.fileSize; }
        }

        /// <summary>
        /// A list of keywords (or tags) that describe the item.
        /// </summary>
        public List<string> KeywordSet
        {
            get { return this.keywordSet; }
            set { this.keywordSet = value; }
        }

        /// <summary>
        /// A description of the item.
        /// </summary>
        public string Description
        {
            get { return this.description; }
            set { this.description = value; }
        }

        /// <summary>
        /// A YouTube video category for the item.
        /// </summary>
        public string Category
        {
            get { return this.category; }
            set { this.category = value; }
        }

        /// <summary>
        /// The URL of the item on YouTube.
        /// </summary>
        public string Url
        {
            get { return this.url; }
            set { this.url = value; }
        }

        /// <summary>
        /// This function is used by the ComboBox control to determine the text to be displayed.
        /// </summary>
        /// <returns>
        /// The string to be displayed in the ComboBox.
        /// </returns>
        public override string ToString()
        {
            return this.originalFileName;
        }

        /// <summary>
        /// Generic equality function.
        /// </summary>
        /// <param name="obj">
        /// An object to compare equality with.
        /// </param>
        /// <returns>
        /// true if this item is equal to the given object and false otherwise.
        /// </returns>
        public override bool Equals(object obj)
        {
            return this == obj as Item;
        }

        /// <summary>
        /// Checks for reference or value equality.
        /// </summary>
        /// <param name="left">
        /// The left hand side of the operator.
        /// </param>
        /// <param name="right">
        /// The right hand side of the operator.
        /// </param>
        /// <returns>
        /// true if the items are equal and false otherwise.
        /// </returns>
        public static bool operator ==(Item left, Item right)
        {
            if (object.ReferenceEquals(left, right))
            {
                return true;
            }
            else if (left is Item && right is Item)
            {
                return left.Id == right.Id;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Checks for reference or value inequality.
        /// </summary>
        /// <param name="left">
        /// The left hand side of the operator.
        /// </param>
        /// <param name="right">
        /// The right hand side of the operator.
        /// </param>
        /// <returns>
        /// true if the items are not equal and false otherwise.
        /// </returns>
        public static bool operator !=(Item left, Item right)
        {
            return !(left == right);
        }

        /// <summary>
        /// Serves as a hash function for Item.
        /// </summary>
        /// <returns>
        /// A hash code.
        /// </returns>
        public override int GetHashCode()
        {
            return this.id.GetHashCode();
        }
    }
}
